import api from '../../api/index'
Page({
  data: {
    userInfo: {
      userName: '',
      cardNum: '',
    },
  },
  onLoad(options) {

  },
  onReady() {

  },
  onShow() {

  },
  changeName(e) {
    const { value } = e.detail
    let userInfo = this.data.userInfo
    let name = e.currentTarget.dataset.name
    userInfo[name] = value
    this.setData({ userInfo })
  },
  submit() {
    const { cardNum, userName } = this.data.userInfo
    if (!cardNum) {
      return wx.showToast({ icon: 'none', title: '请输入身份证号', })
    }
    if (!userName) {
      return wx.showToast({ icon: 'none', title: '请输入用户姓名', })
    }
    const data = { cardNum, userName }
    api.user.schoolFellowSmart(data).then(res => {
      console.log(res)
    }).catch(res => {
      wx.showModal({
        title: '提示',
        content: '自动认证失败，请前往人工认证',
        showCancel: false,
        confirmText: '去认证',
        complete: (res) => {
          wx.redirectTo({
            url: `/pages/authentication/authentication?cardNum=${cardNum}&userName=${userName}`,
          })
        }
      })
    })
  },
})